package com.jsf.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.jsf.entity.Emp;
import com.jsf.entity.Member;
import com.jsf.entity.Tj;
import com.jsf.service.IEmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jsf
 * @since 2022-02-21
 */
@RestController
@RequestMapping("/emp")
public class EmpController {
    @Autowired
    private IEmpService es;
    @GetMapping("/selectAll")
    public List<Emp> selectAll(){
        return es.list();
    }

    @PostMapping("/add")
    public void add(@RequestBody Emp emp){
        es.save(emp);
    }
    @DeleteMapping("/delete/{id}")
    public void delete(@PathVariable("id") int id){
        es.removeById(id);
    }

    @GetMapping("/selectSaleman")
    public List<Emp> selectSaleman(){
        QueryWrapper<Emp> wrapper=new QueryWrapper();
        wrapper.eq("role",3);
        return es.list(wrapper);
    }
    @GetMapping("/login/{username}/{password}")
    public boolean login(@PathVariable("username") String username,
                         @PathVariable("password") String password,
                         HttpSession session){
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("name",username);
        wrapper.eq("pwd",password);
        Emp emp=es.getOne(wrapper);
        if(emp!=null){
            session.setAttribute("user",emp);
            return true;
        }

        return false;
    }

}

